package jjn.kamacoder.case19;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023-08-31 16:33
 */
public class Main {
    
    static class ListNode {
        int val;
        ListNode next;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            ListNode dummy = new ListNode();
            ListNode start = dummy;
            int num = scanner.nextInt();
            if (num == 0) {
                System.out.println("list is empty");
            };
            for (int i = 0; i < num; i++) {
                ListNode node = new ListNode();
                node.val = scanner.nextInt();
                start.next = node;
                start = start.next;
            }
            ListNode head = dummy.next;
            while (head != null) {
                System.out.print(head.val);
                System.out.print(" ");
                head = head.next;
            }
            ListNode node = reverseNode(dummy.next);
            while (node != null) {
                System.out.print(node.val);
                System.out.print(" ");
                node = node.next;
            }
            System.out.println();
        }
    }
    
    private static ListNode reverseNode(ListNode linkedList) {
        if (linkedList == null) {
            return null;
        }
        ListNode cur = linkedList, pre = null;
        while (cur != null) {
            ListNode temp = cur.next;
            cur.next = pre;
            pre = cur;
            cur = temp;
        }
        return pre;
    }
}
